package me.leiusual.sharing.ui.order.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.orderlist.OrderDetail

/**
 * author: leiusual
 * create on: 2019-08-03
 * description:
 */
class OrderListChildAdapter : RecyclerView.Adapter<OrderListChildViewHolder>() {

  private var dataSet = emptyList<OrderDetail>()

  override fun getItemCount(): Int {
    return dataSet.size
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OrderListChildViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_order_list_child, parent, false)
    return OrderListChildViewHolder(itemView)
  }

  override fun onBindViewHolder(holder: OrderListChildViewHolder, position: Int) {
    holder.bind(dataSet[position])
  }

  fun submitList(list: List<OrderDetail>) {
    this.dataSet = list
    notifyDataSetChanged()
  }
}